import express from "express";
import db from "../db/db.js";
import { arrayTranslate } from "../common/arrayTranslate.js";

const getAllFundInfo = express.Router();

const getAllFundNames = async () => {
    return new Promise((resolve, reject) => {
        const sql = `SELECT fundName FROM asset`;
        db.query(sql, (err, results) => {
            if (err) {
                return reject(err);
            }
            resolve(arrayTranslate(results, "fundName"));
        });
    });
};


getAllFundInfo.get("/getAllFund", async (req, res) => {
    try {
        const params = req.body;
        const dataRes: any = await getAllFundNames();
        res.send({
            code: 200,
            message: "修改忽略状态完成 请求成功！",
            result: dataRes,
            // total: dataRes.length,
        });
    } catch (error) {
        console.error("Error fetching file records:", error);
        res.status(500).send({
            code: 1,
            message: "修改忽略状态完成 请求失败！",
            result: null,
        });
    }
});

export default getAllFundInfo;
